package com.action;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.pojo.EmpPOJO;
import com.service.EmpService;
import com.vo.ResponseBean;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/api")
@CrossOrigin("*")
public class EmpAction {

    @Autowired
    private EmpService empService;

    @RequestMapping("/searchEmp")
    public ResponseBean searchEmpWithDepByPage(@RequestParam(defaultValue = "1") int page,@RequestParam(defaultValue = "10") int limit,@RequestParam Map m){

        System.out.println("assd：" + m);
        IPage result = empService.searchEmpWithDepByPage(page, limit, m);
        return new ResponseBean(0,result.getTotal(),result.getRecords());

    }

    @RequestMapping("/changeEmpSex")
    public ResponseBean changeEmpSex(@RequestParam Map m)
    {
        System.out.println(m);
        //得到员工
        EmpPOJO emp = empService.getById((String)m.get("eid"));
        System.out.println("性别1："+emp);
        Integer oldSex = emp.getSex();
        System.out.println("性别2："+oldSex);
        if (oldSex==null)
            oldSex = 0;
        emp.setSex(1-emp.getSex());

        boolean f = empService.updateById(emp);
        int code = f ? 200 : 500;

        return new ResponseBean(code,0,emp);
    }

}

